﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3
{
    public partial class WebForm9 : System.Web.UI.Page
    {
        private DataClassesHealthDataContext dc = new DataClassesHealthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                EmpRegister Semp = (EmpRegister)Session["member"];
                if (Semp == null)
                {
                    Response.Redirect("member.aspx");
                }
            }
        }

        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            string password = this.TextBoxNewPassword.Text;
            changepassword(password);

        }
        public void changepassword(string password)
        {
            EmpRegister Semp = (EmpRegister)Session["member"];
            EmpRegister emp = this.dc.EmpRegisters.Single(h => h.username.Equals(Semp.username));
            string pass = emp.password;
            if (this.TextBoxPasswordCurrent.Text == pass)
            {
                if (this.TextBoxNewPassword.Text == this.TextBoxPasswordConfirm.Text)
                {
                    emp.password = password;
                    dc.SubmitChanges();
                    this.LabelKQ3.Text = "Change Password successful";
                    LabelKQ1.Visible = false;
                    LabelKQ2.Visible = false;
                    LabelKQ3.Visible = true;
                }
                else
                {
                    this.LabelKQ2.Text = "Incorrect password confirmation";
                    LabelKQ3.Visible = false;
                    LabelKQ1.Visible = false;
                    LabelKQ2.Visible = true;

                }
            }
            else
            {
                this.LabelKQ1.Text = "Password not correct";
                LabelKQ3.Visible = false;
                LabelKQ2.Visible = false;
                LabelKQ1.Visible = true;
            }
        }
    }
}